<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>百度地图标记点</title>
    <style type="text/css">
        body, html, #allmap {
            width: 100%;
            height: 100%;
            overflow: hidden;
            margin: 0;
            font-family: "微软雅黑";
        }

        #l-map {
            height: 100%;
            width: 78%;
            float: left;
            border-right: 2px solid #bcbcbc;
        }

        #r-result {
            height: 100%;
            width: 20%;
            float: left;
        }
    </style>
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
    <script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=kaLBv8Axey6j0ZRMAHaYUhGAKVq4KG9K"></script>
</head>
<body>
<div id="allmap"></div>
</body>
<script>
    $(document).ready(function () {
        $.ajax({
            url: 'http://ta.vipgz2.idcfengye.com/EPServer/servlet/web/cargo/findLocation?rid=123456',
            type: 'get',
            dataType: 'json',
            crossDomain: true,
            success: function (data) {
                var rows = data.rows;
                var lon = [];
                var lat = [];
                for (var i = 0; i < rows.length; i++) {
                    lon[i] = rows[i].longitude;
                    lat[i] = rows[i].latitude;
                }
            }
        });
    });

    //模拟json坐标数据
    var lon = [116.301934, 116.508328, 116.365942, 116.408757];
    var lat = [39.977552, 39.919141, 39.996165, 39.995704];

    // 百度地图API功能
    var map = new BMap.Map("allmap");
    //中心点的坐标
    var point = new BMap.Point(116.404556, 39.915378);
    map.centerAndZoom(point, 13);
    //允许滚动缩放
    map.enableScrollWheelZoom(true);
    //添加地图控件
    map.addControl(new BMap.NavigationControl());
    map.addControl(new BMap.ScaleControl({anchor: BMAP_ANCHOR_TOP_LEFT}));
    map.addControl(new BMap.OverviewMapControl());
    map.addControl(new BMap.MapTypeControl());

    for (var i = 0; i < lon.length; i++) {
        var pt = new BMap.Point(lon[i], lat[i]);
        var marker2 = new BMap.Marker(pt);  // 创建标注
        map.addOverlay(marker2);  // 将标注添加到地图中
    }

    var p1 = new BMap.Point(lon[0], lat[0]);
    var p2 = new BMap.Point(lon[1], lat[1]);
    var p3 = new BMap.Point(lon[2], lat[2]);
    var p4 = new BMap.Point(lon[3], lat[3]);

    var driving = new BMap.DrivingRoute(map, {renderOptions: {map: map, autoViewport: true}});
    driving.search(p1, p2, {waypoints: [p3, p4]});//waypoints表示途经点
</script>
</html>